import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';

export interface fileAttributes {
  id: number;
  name: string;
  title: string;
  url: string;
  type: string;
  size: number;
  status?: number;
  userId?: string;
  createAt: Date;
  updateAt: Date;
}

export type filePk = "id";
export type fileId = file[filePk];
export type fileOptionalAttributes = "id" | "status" | "userId";
export type fileCreationAttributes = Optional<fileAttributes, fileOptionalAttributes>;

export class file extends Model<fileAttributes, fileCreationAttributes> implements fileAttributes {
  id!: number;
  name!: string;
  title!: string;
  url!: string;
  type!: string;
  size!: number;
  status?: number;
  userId?: string;
  createAt!: Date;
  updateAt!: Date;


  static initModel(sequelize: Sequelize.Sequelize): typeof file {
    return file.init({
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      primaryKey: true
    },
    name: {
      type: DataTypes.STRING(255),
      allowNull: false,
      comment: "文件系统名"
    },
    title: {
      type: DataTypes.STRING(255),
      allowNull: false,
      comment: "文件原名"
    },
    url: {
      type: DataTypes.STRING(255),
      allowNull: false
    },
    type: {
      type: DataTypes.STRING(255),
      allowNull: false,
      comment: "文件后缀"
    },
    size: {
      type: DataTypes.FLOAT(11,2),
      allowNull: false,
      comment: "文件大小"
    },
    status: {
      type: DataTypes.TINYINT,
      allowNull: true,
      defaultValue: 1,
      comment: "文件状态"
    },
    userId: {
      type: DataTypes.STRING(50),
      allowNull: true
    },
    createAt: {
      type: DataTypes.DATE,
      allowNull: false
    },
    updateAt: {
      type: DataTypes.DATE,
      allowNull: false
    }
  }, {
    sequelize,
    tableName: 'file',
    timestamps: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
    ]
  });
  }
}
